package com.godz.frontData.index;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.godz.mapper.indexSayMapper;
import com.godz.pojo.indexSay;
import org.springframework.web.bind.annotation.*;

import java.util.List;
//主页名人名言
@RestController
public class sayData {
    final
    indexSayMapper sayMapper;

    public sayData(indexSayMapper sayMapper) {
        this.sayMapper = sayMapper;
    }

    @GetMapping("/index/get/indexSay")
    public List<indexSay> getSay(){
        return sayMapper.queryAllSay();
    }
    //查询单个
    @GetMapping("/index/get/indexSay/{intId}")
    public indexSay getOneSay(@PathVariable("intId") Integer integer) {
        return sayMapper.selectOne(
                new QueryWrapper<indexSay>().eq("id", integer)
        );
    }
    //增加一条
    @PostMapping("/index/post/addSay")
    public String addSay(@RequestBody indexSay say) {
        sayMapper.insert(say);
        return "insert OK";
    }
    //修改一条
    @PostMapping("/index/post/editSay")
    public String editSay(@RequestBody indexSay say) {
        QueryWrapper<indexSay> wrapper = new QueryWrapper<>();
        wrapper.eq("id", say.getId());

        indexSay say1 = new indexSay();
        say1.setSayName(say.getSayName());
        say1.setSayEname(say.getSayEname());
        say1.setSayImg(say.getSayImg());
        say1.setSayContent(say.getSayContent());

        sayMapper.update(say1, wrapper);
        return "Update OK";
    }

    //删除一条
    @GetMapping("/index/get/deleteSay/{id}")
    public String deleteTw(@PathVariable("id") Integer integer) {
        sayMapper.deleteById(integer);
        return "Delete Ok";
    }
}
